New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve e2e HostExec utility #84444
Improve e2e HostExec utility #84444
Conversation
// This works like ssh.SSH(...) utility. | ||
func (h *hostExecutor) Execute(cmd string, node *v1.Node) (Result, error) { | ||
result, err := h.exec(cmd, node) | ||
if codeExitErr, ok := err.(exec.CodeExitError); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e2elog.Logf("exec %s: command: %s", remote, result.Cmd) | ||
e2elog.Logf("exec %s: stdout: %q", remote, result.Stdout) | ||
e2elog.Logf("exec %s: stderr: %q", remote, result.Stderr) | ||
e2elog.Logf("exec %s: exit code: %d", remote, result.Code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like ssh.LogResult
, here are some examples:
Oct 28 19:14:21.053: INFO: exec k8s-testing-worker: command: ls -1 /mnt/disks/by-uuid/google-local-ssds-scsi-fs/ | wc -l
Oct 28 19:14:21.053: INFO: exec k8s-testing-worker: stdout: "0\n"
Oct 28 19:14:21.053: INFO: exec k8s-testing-worker: stderr: "ls: cannot access '/mnt/disks/by-uuid/google-local-ssds-scsi-fs/': No such file or directory\n"
Oct 28 19:14:21.053: INFO: exec k8s-testing-worker: exit code: 0
failed command log:
Oct 28 18:59:52.926: INFO: exec k8s-testing-worker: command: ls -1 /mnt/disks/by-uuid/google-local-ssds-scsi-fs/
Oct 28 18:59:52.926: INFO: exec k8s-testing-worker: stdout: ""
Oct 28 18:59:52.926: INFO: exec k8s-testing-worker: stderr: "ls: cannot access '/mnt/disks/by-uuid/google-local-ssds-scsi-fs/': No such file or directory\n"
Oct 28 18:59:52.926: INFO: exec k8s-testing-worker: exit code: 2
// HostExec represents interface we require to execute commands on remote host. | ||
type HostExec interface { | ||
Execute(cmd string, node *v1.Node) (Result, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New method to replace ssh.SSH
.
- separate stdout and stderr - return command exit code - remove kubectl dependency
/priority important-soon |
@@ -1182,9 +1182,10 @@ func validateStatefulSet(config *localTestConfig, ss *appsv1.StatefulSet, anti b | |||
// and skips if a disk of that type does not exist on the node | |||
func SkipUnlessLocalSSDExists(config *localTestConfig, ssdInterface, filesystemType string, node *v1.Node) { | |||
ssdCmd := fmt.Sprintf("ls -1 /mnt/disks/by-uuid/google-local-ssds-%s-%s/ | wc -l", ssdInterface, filesystemType) | |||
res, err := config.hostExec.IssueCommandWithResult(ssdCmd, node) | |||
res, err := config.hostExec.Execute(ssdCmd, node) | |||
utils.LogResult(res) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as an example usage of Execute
method. I didn't remove all IssueCommand/IssueCommandWithResult
use cases. These two methods are simple to use sometimes.
e2epod "k8s.io/kubernetes/test/e2e/framework/pod" | ||
) | ||
|
||
// Result holds the execution result of remote execution command. | ||
type Result struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like ssh.Result
except no User
field
/retest |
result := Result{ | ||
Host: node.Name, | ||
Cmd: cmd, | ||
} | ||
pod, ok := h.nodeExecPods[node.Name] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember @jsafrane hit some issue with creating two host exec pods in the same test. Did that ever get resolved? How about hostexec for two tests running in parallel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A limitation is this utility cannot be shared by multiple parallel tests. We can add support when necessary.
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cofyc, msau42 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #84233
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: